package com.example.jing_android_8;

import androidx.appcompat.app.AppCompatActivity;

import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.MediaController;
import android.widget.VideoView;

import java.io.File;

public class MainActivity extends AppCompatActivity {
    VideoView videoView;
    EditText editText;
    MediaController mController;
    Button button;

    @Override
    protected void onCreate(Bundle savedInstanceState)
    {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        videoView=findViewById(R.id.video);
        button=findViewById(R.id.button);
        editText=findViewById(R.id.edit);
        String url=editText.getText().toString();
        mController=new MediaController(this);
        videoView=findViewById(R.id.video);
        button.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                String url=editText.getText().toString();
                System.out.println(url);
                File video =new File("/storage/emulated/0/"+url);
                System.out.println(video.getAbsolutePath());
                if(video.exists())
                {
                    System.out.println("gett");
                    videoView.setVideoPath(video.getAbsolutePath());
                    videoView.setMediaController(mController);
                    mController.setMediaPlayer(videoView);
                    videoView.requestFocus();
                }

            }
        });



    }

}